// 自定义实现tag 标签
const state = () => ({
  // 用来接收传递过来的路由数组 
  options: [] 
})

const getters = {
  options: (state) => state.options
}

const mutations = {
  changeLayout: (state, layout) => {
    console.log(state, layout);
    let result = false
    for (let i = 0; i < state.options.length; i++) {
      if (state.options[i].path == layout.path) {
        return result = true
      }
    }
    result === false ? state.options.push(layout) : ''
    console.log(state.options);
  },
  closeTag(state,data){
    console.log(state,data);
    let result = state.options.findIndex(item => item.path === data.path)
    state.options.splice(result, 1)
  }
}

const actions = {
  changeLayout({
    commit
  }, layout) {
    console.log({commit},layout)
    commit('changeLayout', layout)
  }
}

export default {
  state,
  mutations,
  getters,
  actions
}
